package com.synjones.handsetS8.ild.net.api;

import com.google.gson.Gson;

import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Retrofit;
import retrofit2.http.Body;
import retrofit2.http.POST;

/**
 * 测试用的
 */
public class HandSetApi {
    private static Retrofit retrofit;
    private static IdCardService service;

    static {
        retrofit = new Retrofit.Builder()
                .baseUrl("http://192.168.101.138:8080/")
                .build();

        service = retrofit.create(IdCardService.class);
    }

    /**
     * 添加身份证信息
     *
     * @param idCardInfo
     */
    public static void addIdCard(Map<String, Object> idCardInfo, Callback<ResponseBody> callback) {
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), new Gson().toJson(idCardInfo));
        Call<ResponseBody> call = service.addIdCard(requestBody);
        call.enqueue(callback);
    }

    /**
     * 添加身份证信息
     *
     * @param nfcInfo
     */
    public static void reportNfcInfo(Map<String, Object> nfcInfo, Callback<ResponseBody> callback) {
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), new Gson().toJson(nfcInfo));
        Call<ResponseBody> call = service.reportNfcInfo(requestBody);
        call.enqueue(callback);
    }


    interface IdCardService {
        /**
         * 添加身份证信息
         *
         * @param body
         * @return
         */
        @POST("api/handset/addIdCard")
        Call<ResponseBody> addIdCard(@Body RequestBody body);

        /**
         * 汇报手环读取信息
         *
         * @param body
         * @return
         */
        @POST("api/handset/reportNfcInfo")
        Call<ResponseBody> reportNfcInfo(@Body RequestBody body);
    }
}
